<?php
/**
 * All data collected by the wizard and stored in the HTTP session.
 */
class SeminarWizardData {

    public static $STEP_SEMINAR = 'seminar';
    public static $STEP_BATCHES = 'seminarBatch';
    public static $STEP_PRICE_GROUPS = 'priceGroup';
    public static $STEP_PROGRAM_TYPES = 'programType';
    public static $STEP_ACCOMODATION_TYPES = 'accomodationType';
    public static $STEP_PRICES = 'price';
    public static $STEP_DISCOUNTS = 'discount';
    public static $STEP_EXTRA_CHARGES = 'extraCharge';
    public static $STEP_SUMMARY = 'summary';

    public static $STEPS; // Initialized below the class declaration

    public $step;

    // Seminar
    public $seminar;

    // Batch
    public $batchList = array();
    public $usedBatchTypeList = array();

    // Price group
    public $priceGroupList = array();

    // Program type
    public $karmayogaTypeCodeList = array();
    public $singleDayProgramTypeList = array();
    public $singleDayAccommodationTypeList = array();
    public $programTypeForm;
    public $karmayogaAvailable; /* boolean */
    public $availableProgramTypeList = array();
    public $exerciseGroupList;

    // Accomodation types
    public $accomodationTypeBatchTable = array();
    public $availableAccomodationTypeList;

    // Prices
    public $priceForm;

    // Discounts
    public $discountForm;

    // Extra charges
    public $chargesForm;
    
    public function __construct() {
        $this->step = self::$STEPS[0];
    }

    public function goBackToStep($step) {
        $this->step = $step;

        switch ($step) {
            case self::$STEP_SEMINAR :
                // When you go to the first step, WizardController will create a new data object.
            case self::$STEP_BATCHES :
                // $this->priceGroupList = array();
            case self::$STEP_PRICE_GROUPS :
                $this->karmayogaTypeCodeList = array();
                $this->singleDayProgramTypeList = array();
                $this->programTypeForm = null;
                $this->karmayogaAvailable = null;
                $this->availableProgramTypeList = array();
                $this->exerciseGroupList = null;
            case self::$STEP_PROGRAM_TYPES :
                $this->accomodationTypeBatchTable = array();
                $this->availableAccomodationTypeList = null;
                $this->singleDayAccommodationTypeList = array();
            case self::$STEP_ACCOMODATION_TYPES :
                $this->priceForm = null;
            case self::$STEP_PRICES :
                $this->discountForm = null;
            case self::$STEP_DISCOUNTS :
                $this->chargesForm = null;
            case self::$STEP_EXTRA_CHARGES :
            default :
                break;
        }
    }

    public function existsBatch($newBatch) {
        foreach ($this->batchList AS $batch) {
            if ($batch['name'] == $newBatch['name']) {
                return TRUE;
            }
        }
        return FALSE;
    }

    public function existsPriceGroup($newPriceGroup) {
        foreach ($this->priceGroupList AS $priceGroup) {
            if ($priceGroup['name'] == $newPriceGroup['name']) {
                return TRUE;
            }
        }

        return FALSE;
    }

    public function countryCodesInPriceGroups() {
        $codes = array();
        foreach ($this->priceGroupList as $priceGroup) {
            if (is_array($priceGroup['country_codes'])) {
                $codes = array_merge($codes, $priceGroup['country_codes']);
            }
        }
        return $codes;
    }
}

// This array sets the order of the wizard steps
SeminarWizardData::$STEPS = array(
        SeminarWizardData::$STEP_SEMINAR,
        SeminarWizardData::$STEP_BATCHES,
        SeminarWizardData::$STEP_PRICE_GROUPS,
        SeminarWizardData::$STEP_PROGRAM_TYPES,
        SeminarWizardData::$STEP_ACCOMODATION_TYPES,
        SeminarWizardData::$STEP_PRICES,
        SeminarWizardData::$STEP_DISCOUNTS,
        SeminarWizardData::$STEP_EXTRA_CHARGES,
        SeminarWizardData::$STEP_SUMMARY
);
